<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-trophy"></i> 企业管理
            </div>
            <div class="box-tools pull-right">
                <a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
                <sec:authorize access="hasRole('ROLE_ADMIN_ENTERPRISE_EDIT')">
                <a href="javascript:;" onclick="addEnterprise();" class="btn btn-default btnTool"
                   title="新增企业"><i class="fa fa-plus"></i> 新增</a>
                </sec:authorize>
            </div>
        </div>
        <div class="box-body">
            <form id="searchForm" action="<c:url value="/web/admin/enterprise/listJson.action"/>" method="post"
                  class="form-inline hide" data-page-no="1" data-page-size="20" data-order-by="">
                <div class="form-group">
                    <label class="control-label">企业名称：</label>
                    <div class="control-inline">
                        <input type="text" id="enterpriseName" name="enterpriseName" value="" maxlength="64"
                               class="form-control width-120">
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label">企业编码：</label>
                    <div class="control-inline">
                        <input type="text" id="code" name="code" value="" maxlength="64"
                               class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">查询</button>
                    <button type="reset" class="btn btn-default btn-sm">重置</button>
                </div>
            </form>

            <table id="dataGrid"></table>
            <div id="dataGridPage"></div>
        </div>
    </div>
</div>
<script>
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        columnModel: [
            {
                header: '操作',
                name: 'actions',
                width: 250,
                align: "center",
                sortable: false,
                title: false,
                formatter: function (val, obj, row, act) {
                    return ""+
                        <%--<sec:authorize access="hasRole('ROLE_ADMIN_ENTERPRISE_EDIT')">--%>
                        '<a  class="btn btn-default btn-xs btnList" onclick="editEnterprise(' + row.id + ')" title="编辑企业"><i class="fa fa-pencil"></i>编辑企业</a>&nbsp;'+
                        '<a  class="btn btn-default btn-xs btnList" onclick="editChildEnterprise(' + row.id + ')" title="编辑子企业"><i class="fa fa-pencil"></i>编辑子企业</a>&nbsp;'+
                        <%--</sec:authorize>--%>
                        '<a  class="btn btn-default btn-xs btnList" onclick="editEnterpriseSysUser(' + row.id + ')" title="添加管理者"><i class="fa fa-pencil"></i>添加管理者</a>&nbsp;' +
                        '<a  class="btn btn-default btn-xs btnList" onclick="userDetail(' + row.id + ')" title="查看管理者"><i class="fa fa-pencil"></i>查看管理者</a>&nbsp;'
                }
            },
            /*{header: '内部编码', name: 'id', index: 'id', width: 50, align: "center",hidden:"true"},*/
            {header: '企业编号', name: 'code', index: 'code', width: 100, align: "center"},
            {header: '企业名称', name: 'enterpriseName', index: 'enterpriseName', width: 100, align: "center"},
            {header: '创建时间', name: 'createDate', index: 'createDate', width: 100, align: "center"},
            {header: '创建人', name: 'createUser', index: 'createUser', width: 100, align: "center"}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function (data) {

        }
    });

    function editEnterprise(id) {
        vLayuiUtil.openLayerWindow('wEnterprise', '<c:url
                        value="/web/admin/enterprise/editPage.action?id="/>' + id, '编辑')
    }
    function editChildEnterprise(id) {
        vLayuiUtil.openLayerWindow('wChildEnterprise', '<c:url
                        value="/web/admin/enterprise/editChildPage.action?id="/>'+id , '新增企业',["100%","100%"])
    }

    function editEnterpriseSysUser(id) {
        vLayuiUtil.openLayerWindow('wSysUserEnterprise', '<c:url
                        value="/web/admin/enterprise/editSysUserPage.action?id="/>' + id, '企业管理者')
    }

    function addEnterprise() {
        vLayuiUtil.openLayerWindow('wChildEnterprise', '<c:url
                        value="/web/admin/enterprise/editChildPage.action?id=1"/>' , '新增企业',["100%","100%"])
    }

    function userDetail(id){
        vLayuiUtil.openLayerWindow('wUserDetail', '<c:url
                        value="/web/admin/enterprise/sysUserDetailPage.action?id="/>' + id, '查看企业管理者',["80%","80%"])
    }
</script>